<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js"></script>
</head>

<body>
    <div id="app">
        <!-- 基本类型直接修改 会重新渲染页面 -->
        <button @click = "count+=10">修改count</button>
        {{count}}
        <br/>

        <button @click = "forceUpdate">强制刷新</button>
        <br/>

        <!-- vue监听对象属性的变化 但是添加或删除属性vue检测不到 重新渲染 -->
        <button @click = "person.name1 = '666' ">修改对象</button>

        <!-- 不重新渲染 -->
        <button @click = "person.name5 = '777' ">对象添加属性</button>
        <button @click = "delete person.name1">对象删除属性</button>
        <br/>

        <!-- 用vue提供地方法添加删除对象可以直接重新渲染 -->
        <button @click = "add">vue-添加属性</button>
        <button @click = "dalete">vue-删除属性</button>

        <ul>
            <li v-for = "item in person" key = "Date.now()">{{item}}</li>
        </ul>
    </div>
    <script>
        Vue.config.productionTip = false;
        
        const vm = new Vue({
            el: "#app",
            data() {
                return {
                    //基本类型直接修改 重新渲染
                    count: 0,
                    //对象类型修改了属性会重新渲染 添加和删除不会
                    person:{
                        name1: "云南",
                        name2: "西安",
                        name3: "大理",
                        name4: "丽江",
                    }
                }
            },
            methods:{
                forceUpdate(){
                    this.$forceUpdate()
                },
                //添加
                add(){
                    //实例上地方法:
                    // this.$set(this.person , "age" , "北京")
                    // vm.$set(this.person , "age" , "北京")

                    //Vue上的方法
                    Vue.set(this.person , Date.now() , "北京")
                },
                //删除
                dalete(){
                    //实例上地方法
                    // vm.$delete(this.person , "name1")
                    // this.$delete(this.person , "name1")

                    //Vue上地方法
                    Vue.delete(this.person , "name1")

                }
            }
        })
    </script>
</body>

</html>